package com.example.ormsqlsplicingframe1.aop;


import com.example.ormsqlsplicingframe1.session.SessionUtil;

import com.example.ormsqlsplicingframe1.utlis.ProxySessionUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


@Aspect
@Order(9998)
@Component
public class TransactionAop {


    /**
     * 配置切入点
     */
    @Pointcut("@annotation(org.springframework.transaction.annotation.Transactional)"+ "|| @within(org.springframework.transaction.annotation.Transactional)")
    public void apoPointCut() {
        // 无方法体，主要在@Pointct中体现@AopTest注解类所在位置
    }


    @Around("apoPointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {


        try {



            SessionUtil.getSession().startTransaction(true);

            Object val =  joinPoint.proceed();


            SessionUtil.getSession().commitTransaction();


            return val;
        }catch (Exception e){
            SessionUtil.getSession().rollbackTransaction();
            throw e;
        }finally {

        }

    }

}
